package com.antball.aaa.command_responsibilitychain_design;

import com.antball.aaa.command_responsibilitychain_design.model.CommandVo;
import javafx.beans.Observable;

import java.util.Observer;

/**
 * @Auther: huangsj
 * @Date: 2019/8/6 17:40
 * @Description:
 */
public abstract class CommandName {

    private CommandName nextOperator;

    public final String handlerMessage(CommandVo commandVo){
        String result="";

        if(commandVo.getParamList().size()==0 || commandVo.getParamList().contains(this.getOperatorParam())){
            result = this.echo(commandVo);
        }else {
            if(this.nextOperator!= null){
                return nextOperator.handlerMessage(commandVo);
            }else {
                result= "命令无法执行";
            }
        }

        return result;
    }

    public void setNext(CommandName commandName){
        this.nextOperator = commandName;
    }

    protected abstract String getOperatorParam();


    protected abstract String echo(CommandVo commandVo);

}
